package org.fengling.readingplatform.note.controller;

import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.fengling.readingplatform.model.entity.note.Note;
import org.fengling.readingplatform.model.vo.common.Result;
import org.fengling.readingplatform.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.fengling.readingplatform.note.service.NoteService;

@RestController
@RequestMapping("api/note")
public class NoteController {

    @Autowired
    private NoteService noteService;

    // 发布阅读笔记的方式
    @PostMapping(value = "/saveNote")
    public Result saveNovel(@RequestBody Note note){
        noteService.save(note);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    // 分页查询阅读笔记的方式
    @GetMapping(value = "/findByPage/{pageNum}/{pageSize}")
    public Result findByPage(@PathVariable("pageNum") Integer pageNum,
                             @PathVariable("pageSize") Integer pageSize){
        PageInfo<Note> pageInfo = noteService.findByPage(pageNum, pageSize);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }


}
